/*
 * Copyright (c) 2015. For Intelligent Group.
 */
package com.intelligent.ispc.core.entity;

import com.google.common.collect.Lists;
import com.intelligent.ispc.common.persistence.BaseEntity;
import com.intelligent.ispc.utils.ResourceCategory;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.List;

/**
 * Created by Roevy.Luo on 2015/10/28.
 */

@Entity
@Table(name = "t_resource")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Resource extends BaseEntity {
    private String code;
    private String name;

    @Enumerated(EnumType.STRING)
    private ResourceCategory category;

    private String description;

    @ManyToMany(targetEntity = Role.class, mappedBy = "resources",
            cascade = {CascadeType.PERSIST}, fetch = FetchType.EAGER)
    private List<Role> roles = Lists.newArrayList();

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public ResourceCategory getCategory() {
        return category;
    }

    public void setCategory(ResourceCategory category) {
        this.category = category;
    }
}
